package services

import (
	"gobuild/config"
	"gobuild/models"
	"io"
	"io/ioutil"
	"os"

	yaml "gopkg.in/yaml.v2"
)

//配置操作相关
type configurationService struct{}

func (this *configurationService) SaveGlobalToolConfiguration(content map[string]interface{}) (err error) {

	f, err := os.OpenFile(config.HomePath+"/config/globaltool.yml", os.O_RDWR|os.O_CREATE, 0644)
	d, err := yaml.Marshal(content)

	_, err = io.WriteString(f, string(d)) //写入文件(字符串)
	defer f.Close()

	return
}

func (this *configurationService) GetGlobalToolConfiguration() (content models.GlobalToolConfig, err error) {
	bytes, err := ioutil.ReadFile(config.HomePath + "/config/globaltool.yml")
	err = yaml.Unmarshal(bytes, &content)

	return
}
